package stock

import (
	"context"
	"time"

	"github.com/nats-io/nats.go/jetstream"
)

func createCustomer(ctx context.Context, customerName string, js jetstream.JetStream, streamName string, subject string) jetstream.Consumer {
	customer, _ := js.CreateOrUpdateConsumer(ctx, streamName, jetstream.ConsumerConfig{
		Name:          customerName,
		Durable:       customerName,
		FilterSubject: subject,
		DeliverPolicy: jetstream.DeliverAllPolicy,
		AckPolicy:     jetstream.AckExplicitPolicy,
		MaxAckPending: 1,                // 关键：确保单条处理
		AckWait:       10 * time.Second, // 快速超时
		MaxDeliver:    3,                // 重试3次
	})

	return customer
}
